package com.sleepcamel.rest.domain;

import java.util.ArrayList;
import java.util.List;

public class ProjectPackage extends TreeNode{

	public ProjectPackage(){}
	
	public ProjectPackage(String name){
		setName(name);
	}
	
	public List<Mapping> getAllPackageMappings(){
		ArrayList<Mapping> arrayList = new ArrayList<Mapping>();
		List<TreeNode> childs = getChilds();
		for(TreeNode child:childs){
			if ( child instanceof Mapping ){
				arrayList.add((Mapping) child);
			}else{
				if ( child instanceof ProjectPackage ){
					arrayList.addAll(((ProjectPackage) child).getAllPackageMappings());
				}
			}
		}
		return arrayList;
	}

	public String getPackageName() {
		if ( getParent() instanceof Project )
			return getName();
		
		ProjectPackage projectPackage = getParent();
		return projectPackage.getPackageName() + "." + getName();
	}
}
